import java.awt.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.swing.*;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;



public class MinPersonnage extends JPanel{

	public MinPersonnage(Personnage p) {
		setLayout(new GridLayout(2, 1));
		setBorder(BorderFactory.createLineBorder(Color.black));

		JPanel panel_TOP = new JPanel();
		add(panel_TOP);
		GridBagLayout gbl_panel_TOP = new GridBagLayout();
		gbl_panel_TOP.columnWidths = new int[] { 10, 170, 70, 0 };
		gbl_panel_TOP.rowHeights = new int[] { 50, 0 };
		gbl_panel_TOP.columnWeights = new double[] { 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		gbl_panel_TOP.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
		panel_TOP.setLayout(gbl_panel_TOP);

		JLabel marg1 = new JLabel("");
		GridBagConstraints gbc_marg1 = new GridBagConstraints();
		gbc_marg1.insets = new Insets(0, 0, 0, 5);
		gbc_marg1.gridx = 0;
		gbc_marg1.gridy = 0;
		panel_TOP.add(marg1, gbc_marg1);

		JLabel nom = new JLabel(p.getNom());
		nom.setAlignmentX(Component.RIGHT_ALIGNMENT);
		GridBagConstraints gbc_nom = new GridBagConstraints();
		gbc_nom.anchor = GridBagConstraints.CENTER;
		gbc_nom.insets = new Insets(0, 0, 0, 5);
		gbc_nom.gridx = 1;
		gbc_nom.gridy = 0;
		panel_TOP.add(nom, gbc_nom);

		JLabel lvl = new JLabel("Lvl : " + Integer.toString(p.getNiveau()));
		GridBagConstraints gbc_lvl = new GridBagConstraints();
		gbc_lvl.anchor = GridBagConstraints.WEST;
		gbc_lvl.gridx = 2;
		gbc_lvl.gridy = 0;
		panel_TOP.add(lvl, gbc_lvl);

		JPanel panel_BOT = new JPanel();
		add(panel_BOT);
		GridBagLayout gbl_panel_BOT = new GridBagLayout();
		gbl_panel_BOT.columnWidths = new int[] { 10, 170, 70, 0 };
		gbl_panel_BOT.rowHeights = new int[] { 50, 0 };
		gbl_panel_BOT.columnWeights = new double[] { 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		gbl_panel_BOT.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
		panel_BOT.setLayout(gbl_panel_BOT);

		JLabel marg2 = new JLabel("");
		GridBagConstraints gbc_marg2 = new GridBagConstraints();
		gbc_marg2.insets = new Insets(0, 0, 0, 5);
		gbc_marg2.gridx = 0;
		gbc_marg2.gridy = 0;
		panel_BOT.add(marg2, gbc_marg2);

		JLabel ev = new JLabel(Integer.toString(p.getEnergieVitaleActuelle()) + "/" + Integer.toString(p.getEnergieVitaleMax()));
		GridBagConstraints gbc_ev = new GridBagConstraints();
		gbc_ev.anchor = GridBagConstraints.CENTER;
		gbc_ev.insets = new Insets(0, 0, 0, 5);
		gbc_ev.gridx = 1;
		gbc_ev.gridy = 0;
		panel_BOT.add(ev, gbc_ev);

		JLabel cou = new JLabel("Cou : " + Integer.toString(p.getCourage()));
		GridBagConstraints gbc_cou = new GridBagConstraints();
		gbc_cou.anchor = GridBagConstraints.WEST;
		gbc_cou.gridx = 2;
		gbc_cou.gridy = 0;
		panel_BOT.add(cou, gbc_cou);
		
		addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {
				Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); 
			     setCursor(cursor);
			     ((JComponent) e.getComponent()).setBorder(BorderFactory.createLineBorder(Color.red));
			}

			@Override
			public void mouseExited(MouseEvent e) {
				Cursor cursor = Cursor.getDefaultCursor();
				setCursor(cursor);
				((JComponent) e.getComponent()).setBorder(BorderFactory.createLineBorder(Color.black));
				

			}
		});
		
		
	}
/*
	public static void main(String[] arg){
		try {
			Personnage p = null;
			// lecture du fichier
			InputStream flux = new FileInputStream("personnage.csv");
			InputStreamReader lecture = new InputStreamReader(flux);
			BufferedReader buff = new BufferedReader(lecture);

			String ligne;
			ligne = buff.readLine();

			while ((ligne = buff.readLine()) != null) {
				String[] tab = ligne.split("\t");
				p = new Personnage(tab[0], tab[1], tab[2], tab[3],
						Integer.parseInt(tab[4]), Integer.parseInt(tab[5]),
						Integer.parseInt(tab[6]), Integer.parseInt(tab[7]),
						Integer.parseInt(tab[8]), Integer.parseInt(tab[9]),
						Integer.parseInt(tab[10]), Integer.parseInt(tab[11]),
						Integer.parseInt(tab[12]), Integer.parseInt(tab[13]),
						Integer.parseInt(tab[14]), Integer.parseInt(tab[15]),
						Integer.parseInt(tab[16]), Integer.parseInt(tab[17]),
						Integer.parseInt(tab[18]), Integer.parseInt(tab[19]),
						tab[20]);
			}
			System.out.println(p.toString());
			buff.close();
			
			FenetrePrincipale f = new FenetrePrincipale();
			MinPersonnage m = new MinPersonnage(p);
			f.add(m);
		} catch (Exception e) {
			System.out.println(e.toString());
		}
		
	}*/
}
